package com.ttbj.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class TokenUtils {
	private static long orderNum = 0l;
	private static SimpleDateFormat format = new SimpleDateFormat("yyMMdd");

	/**
	 * 生成token
	 * 
	 * @return
	 */
	public static String create() {
		return UUID.randomUUID().toString();
	}

	/**
	 * 生成License
	 * 
	 * @return
	 */
	public static String licenseCreate() {
		return UUID.randomUUID().toString();
	}

	/**
	 * 生成单纯数字的订单编号
	 * 
	 * @return
	 */
	private static synchronized String getOrderNo(String date, Long time) {
		String str = format.format(new Date(time)); // 当前的日期
		if (date == null || !date.equals(str)) { // 如果日期和当天日期生成的订单号不一样
			date = str;
			orderNum = 0l;
		}
		++orderNum;
		long orderNo = Long.parseLong((date)) * 100000;
		orderNo += orderNum;
		return orderNo + "";
	}

	/**
	 * 生成包含有字母的订单编号
	 * @param pexStr	前置 
	 * 
	 * @return
	 */
	public static synchronized String getNo(String pexStr) {
		long time = System.currentTimeMillis();
		String split = time + "";
		split = split.substring(9, 13);
		String date = format.format(new Date(time));
		String orderNo = getOrderNo(date, time);
		return pexStr + split + orderNo;
	}
	

}
